package org.orcean.com.common.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * @Author BigKang
 * @Date 2020/1/14 2:15 PM
 * @Summarize 统一返回Vo对象
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class ResultVo implements Serializable {

    private Object data;
    private Integer code;
    private String message = Message.OK;

    public ResultVo(Object data,Integer code) {
        this.code = code;
        this.data = data;
    }

    public ResultVo(Integer code) {
        this.code = code;
    }

    public ResultVo(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static ResultVo result(Integer code, String message){
        return new ResultVo(code,message);
    }

    public static ResultVo result(Object data){
        return new ResultVo(data,Code.OK_CODE,Message.OK);
    }

    public static ResultVo result(Object data,Integer code, String message){
        return new ResultVo(data,code,message);
    }

    public static ResultVo result(Object data,Integer code){
        return new ResultVo(data,code);
    }

    public static ResultVo error(String message){
        return new ResultVo(Code.ERROR_CODE,message);
    }

    public static ResultVo ok(){
        return new ResultVo(null,Code.OK_CODE);
    }

    public static ResultVo ok(Object data){
        return new ResultVo(data,Code.OK_CODE);
    }
}
